package com.ruoyi.web.invest.asset.moneytrack.service.impl;

import java.util.List;

import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.framework.web.service.TokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.web.invest.asset.moneytrack.mapper.MoneyTrackMapper;
import com.ruoyi.web.invest.asset.moneytrack.domain.MoneyTrack;
import com.ruoyi.web.invest.asset.moneytrack.service.IMoneyTrackService;

/**
 * 资金用途追踪Service业务层处理
 *
 * @author houxuzhong
 * @date 2021-08-25
 */
@Service
public class MoneyTrackServiceImpl implements IMoneyTrackService
{
    @Autowired
    private MoneyTrackMapper moneyTrackMapper;
    @Autowired
    private TokenService tokenService;

    /**
     * 查询资金用途追踪
     *
     * @param id 资金用途追踪主键
     * @return 资金用途追踪
     */
    @Override
    public MoneyTrack selectMoneyTrackById(Long id)
    {
        return moneyTrackMapper.selectMoneyTrackById(id);
    }

    /**
     * 查询资金用途追踪列表
     *
     * @param moneyTrack 资金用途追踪
     * @return 资金用途追踪
     */
    @Override
    public List<MoneyTrack> selectMoneyTrackList(MoneyTrack moneyTrack)
    {
        LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
        SysUser user = loginUser.getUser();
        moneyTrack.setCreateById(user.getUserId());
        moneyTrack.setCreateBy(user.getUserName());
        return moneyTrackMapper.selectMoneyTrackList(moneyTrack);
    }

    /**
     * 新增资金用途追踪
     *
     * @param moneyTrack 资金用途追踪
     * @return 结果
     */
    @Override
    public int insertMoneyTrack(MoneyTrack moneyTrack)
    {
        moneyTrack.setCreateTime(DateUtils.getNowDate());
        return moneyTrackMapper.insertMoneyTrack(moneyTrack);
    }

    /**
     * 修改资金用途追踪
     *
     * @param moneyTrack 资金用途追踪
     * @return 结果
     */
    @Override
    public int updateMoneyTrack(MoneyTrack moneyTrack)
    {
        moneyTrack.setUpdateTime(DateUtils.getNowDate());
        return moneyTrackMapper.updateMoneyTrack(moneyTrack);
    }

    /**
     * 批量删除资金用途追踪
     *
     * @param ids 需要删除的资金用途追踪主键
     * @return 结果
     */
    @Override
    public int deleteMoneyTrackByIds(Long[] ids)
    {
        return moneyTrackMapper.deleteMoneyTrackByIds(ids);
    }

    /**
     * 删除资金用途追踪信息
     *
     * @param id 资金用途追踪主键
     * @return 结果
     */
    @Override
    public int deleteMoneyTrackById(Long id)
    {
        return moneyTrackMapper.deleteMoneyTrackById(id);
    }
}
